function formatTs(ts) {
    var date = new Date(ts);
// hours part from the timestamp
    var hours = date.getHours();
    var appendH0 = hours < 10 ? '0' : '';
// minutes part from the timestamp
    var minutes = date.getMinutes();
    var appendM0 = minutes < 10 ? '0' : '';
// seconds part from the timestamp
    var seconds = date.getSeconds();

    var appendS0 = seconds < 10 ? '0' : '';
// will display time in 10:30:23 format
    var formattedTime = appendH0 + hours + ':' + appendM0 + minutes + ':' + appendS0 + seconds;
    return formattedTime;
}
function getData(indexDiv, valProp, startTime, endTime, callback) {
    $.getJSON("/smart-wheel/data-store/ts/" + startTime + "/" + endTime, function (data) {
        var chartData = {};
        console.log(data);
        chartData.values = [];
        chartData.labels = [];
        chartData.anchors = [];
        chartData.tooltips = [];
        chartData.sumedValues=0;
        $.each(data, function (key, val) {
            chartData.sumedValues+=val[valProp];
            if ((key % indexDiv )== 0) {
                chartData.values.push(val[valProp]);
                var tsFormated = formatTs(val.ts);
                chartData.labels.push(tsFormated);
                var tooltip = "<div class='label'><p class='charlab'>" + val[valProp] + "</p><p class='date'>" + tsFormated + "</p></div>";
                chartData.tooltips.push(tooltip);
            }
//            chartData.anchors.push(val.ts);
        });
        callback(chartData);
    });
}

function currentTimestamp() {
    var d = new Date();
    var currentTime = d.getTime();
    console.log(currentTime);
    return currentTime;
}